package com.test.ds.recursion;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TriangleApp {
	static int theNumber;

	public static void main(String[] args) throws IOException {
		System.out.print("Enter a number: ");
		theNumber = getInt();
		int theAnswer = triangle(theNumber);
		System.out.println("Trangle = " + theAnswer);
	}

	private static int triangle(int n) {
		System.out.println("Entering: n = " + n);
		if (n == 1) {
			System.out.println("Returning 1");
			return 1;
		} else {
			int temp = n + triangle( n - 1 );
			System.out.println("Returning " + temp);
			return temp;
		}
	}

	// private static int triangle(int n) {
	// if(n==1){
	// return 1;
	// }else{
	// return ( n + triangle(n - 1) );
	// }
	// }

	private static int getInt() throws IOException {
		String s = getString();
		return Integer.parseInt(s);
	}

	private static String getString() throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String s = br.readLine();
		return s;
	}

}
